import { User, UserProfile } from '@/types/data'
import { Profile, UserAction } from '@/types/store'

type UserActio = {
  user: User
  userProfile: UserProfile
}
const initialState = {
  user: {},
  userProfile: {},
} as UserActio
export const profile = (
  state = initialState,
  action: Profile | UserAction
): UserActio => {
  switch (action.type) {
    case 'profile/get':
      return { ...state, user: action.payload }
    case 'profile/user':
      return { ...state, userProfile: action.payload }
    case 'profile/update':
      return {
        ...state,
        userProfile: {
          ...state.userProfile,
          ...action.payload,
        },
      }
    case 'profile/photo':
      return {
        ...state,
        userProfile: { ...state.userProfile, photo: action.payload },
      }
    default:
      return state
  }
}
